package com.audaque.springboot.foshanupload.web.streamdemo.dynamice.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cloud.stream.config.BindingProperties;
import org.springframework.cloud.stream.config.BindingServiceProperties;
import org.springframework.cloud.stream.function.StreamBridge;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;
import java.util.Set;

@RequestMapping("streamBridge")
@RestController
public class StreamBridgeController {
    @Autowired(required = false)
    private StreamBridge streamBridge;
    @Autowired(required = false)
    private BindingServiceProperties bindingServiceProperties;


    @GetMapping("/send")
    public void send() {
        Map<String, BindingProperties> bindings = bindingServiceProperties.getBindings();
        Set<String> bindingNameSet = bindings.keySet();
        streamBridge
                .send(
                        "myTopic-out-0",
                        MessageBuilder.withPayload("sb")
                                .setHeader("for", "这是一个请求头～")
                                .build());   }


}
